<template>
   <div>
    <CategoryHeadVue them="新增地址"></CategoryHeadVue>
    <van-address-edit
    :area-list="areaList"
    show-delete
    show-set-default
    show-search-result
    :search-result="searchResult"
    :area-columns-placeholder="['请选择', '请选择', '请选择']"
    @save="onSave"
    @delete="onDelete"
    @change-detail="onChangeDetail"
    />
   </div>
</template>

<script>
import { areaList } from '@vant/area-data';
import { Toast} from 'vant';
import CategoryHeadVue from '@/components/Category-head.vue';
import axios from '@/Utils/server';
let userid = localStorage.getItem("userid")
export default {
 name:"useraddaderss-vue",
 components:{
    CategoryHeadVue
 },
 data() {
    return {
      areaList,
      searchResult: [],
    };
  },
  methods: {
    onSave(info) {
      axios({
      method:"post",
      url:"http://121.89.205.189:3001/api/address/add",
      data:{
          userid:userid,
          name:info.name,
          tel:info.tel,
          province:info.province,
          city:info.city,
          county:info.county,
          addressDetail:info.addressDetail,
          isDefault:info.isDefault
      }
      })
      .then(res=>{
      console.log(res.data);
      if(res.data.code==200){
        this.$router.back()
      }
    })
  },
    onDelete() {
      Toast('delete');
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区',
          },
        ];
      } else {
        this.searchResult = [];
      }
    },
}

}
</script>

<style>

</style>